package com.appkubes.mall.admin.application.goods.goods.service.impl;

import com.appkubes.mall.admin.application.goods.goods.dao.GoodsDao;
import com.appkubes.mall.admin.application.goods.goods.service.GoodsExtendService;
import com.appkubes.mall.admin.application.goods.goods.service.GoodsService;
import com.appkubes.mall.admin.application.system.config.service.ConfigService;
import com.appkubes.mall.core.entity.MallGoods;
import com.appkubes.mall.core.service.impl.BaseMallGoodsServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GoodsServiceImpl extends BaseMallGoodsServiceImpl implements GoodsService {
    @Resource
    GoodsExtendService goodsExtendService;


    @Autowired
    GoodsDao goodsDao;

    @Autowired
    ConfigService configService;


    public int batchenable(String[] ids) {
        return goodsDao.batchenable(ids);
    }


    public List<MallGoods> getCombinationGoods(List<String> ids) {
        QueryWrapper<MallGoods> queryWrapper = new QueryWrapper<>();

        MallGoods entity = new MallGoods();
        queryWrapper.notIn("type", 1);
        queryWrapper.setEntity(entity);

        if (ids.size() > 0) {
            queryWrapper.notIn("goods_key", ids);
        }

        return this.getBaseMapper().selectList(queryWrapper);
    }


    public int batchunenable(String[] ids) {
        return goodsDao.batchunenable(ids);
    }


    /**
     * 以mall_goods表为中心，删除相关星型的数据结构
     *
     * @param ids
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean delete(List<String> ids) {
        this.removeByIds(ids);
        goodsExtendService.removeByIds(ids);
        return true;
    }
}
